package com.neusmart.common.view;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.neusmart.common.R;

public class MyToast extends Toast {

    public MyToast(Context context) {
        super(context);
    }

    public static void showImgAndTextToast(Context context, int resid,
                                           int textid) {
        showImgAndTextToast(context, resid, context.getString(textid));
    }

    public static void showImgAndTextToast(Context context, int resid,
                                           CharSequence text) {
        MyToast result = new MyToast(context);
        View v = LayoutInflater.from(context).inflate(R.layout.view_tips, null);
        // ImageView
        ImageView img = (ImageView) v.findViewById(R.id.tips_icon);
        img.setVisibility(View.VISIBLE);
        img.setBackgroundResource(resid);
        // TextView
        TextView tv = (TextView) v.findViewById(R.id.tips_msg);
        tv.setVisibility(View.VISIBLE);
        tv.setText(text);
        // setView
        result.setView(v);
        // setGravity方法用于设置位置，此处为垂直居中
        result.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        result.setDuration(LENGTH_SHORT);
        result.show();
    }

    public static void showImgToast(Context context, int resid) {
        MyToast result = new MyToast(context);
        View v = LayoutInflater.from(context).inflate(R.layout.view_tips, null);
        // ImageView
        ImageView img = (ImageView) v.findViewById(R.id.tips_icon);
        img.setVisibility(View.VISIBLE);
        img.setBackgroundResource(resid);
        // setView
        result.setView(v);
        // setGravity方法用于设置位置，此处为垂直居中
        result.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        result.setDuration(LENGTH_SHORT);
        result.show();
    }

    public static void showTextToast(Context context, int textId) {
        showTextToast(context, context.getString(textId));
    }

    public static void showTextToast(Context context, CharSequence text) {
        MyToast result = new MyToast(context);
        View v = LayoutInflater.from(context).inflate(R.layout.view_tips, null);
        // TextView
        TextView tv = (TextView) v.findViewById(R.id.tips_msg);
        tv.setVisibility(View.VISIBLE);
        tv.setText(text);
        // setView
        result.setView(v);
        // setGravity方法用于设置位置，此处为垂直居中
        result.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        result.setDuration(LENGTH_SHORT);
        result.show();
    }

}
